package com.ld.security.server.admin.modules.ge.api;

import com.ld.security.common.core.util.ReflectionUtil;
import com.ld.security.common.core.util.StringUtil;
import com.ld.security.common.mybatis.base.po.IdPo;
import com.ld.security.common.mybatis.base.po.PagePo;
import com.ld.security.common.mybatis.base.vo.PageVo;
import com.ld.security.common.tomcat.anno.AjaxLogKey;
import com.ld.security.server.admin.modules.ge.entity.GeViewEntity;
import com.ld.security.server.admin.modules.ge.entity.GeViewTelEntity;
import com.ld.security.server.admin.modules.ge.service.IGeViewTelService;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.tomcat.base.api.SuperApi;
import com.ld.security.server.admin.modules.ge.vo.GeViewTelVo;
import com.ld.security.server.admin.modules.ge.vo.ViewTelSaveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.regex.Pattern;

@RestController
@Api(tags="抽象视图Api管理")
@RequestMapping("/api/geViewTel")
public class GeViewTelApi extends  SuperApi<GeViewTelEntity> {

    Pattern p = Pattern.compile("\\s*|\t|\r|\n");

    @Autowired
    IGeViewTelService iGeViewTelService;

    @ApiOperation("代码测试")
    @RequestMapping(value = "/getCode",method = RequestMethod.POST)
    public DataVo getCode(){
        GeViewTelEntity geView =  iGeViewTelService.getById("0");
        return DataVo.of(geView);
    }
    @AjaxLogKey
    @ApiOperation("得到视图模板修改数据")
    @RequestMapping(value = "/getViewTelSave",method = RequestMethod.POST)
    public DataVo getViewTelSaveVo(   @RequestBody IdPo po){
        ViewTelSaveVo geView = null;
        if(StringUtil.isNotNull(po.getId())){
            geView =  iGeViewTelService.getViewTelSaveVo(po.getId());
        }else{
            geView = new ViewTelSaveVo();
            ReflectionUtil.fill(geView);
        }

        return DataVo.of(geView);
    }
    @AjaxLogKey
    @ApiOperation("修改视图模板")
    @RequestMapping(value = "/saveViewTel",method = RequestMethod.POST)
    public DataVo saveViewTel( @Valid  @RequestBody ViewTelSaveVo po){
         iGeViewTelService.saveViewTel(po);
        return DataVo.ofMsg("修改成功");
    }


//    @AjaxLogKey
//    @RequestMapping(value = "/page", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation("分页查询数据")
//    @Override
//    public DataVo<PageVo<GeViewTelEntity>> page(@RequestBody @Valid PagePo<GeViewTelEntity> po) {
//        po.getQuery().setScopeType(GeScopeConstant.scopeType.glbal);
//
//        GeViewTelVo q = JsonUtil.clone(po.getQuery(),GeViewTelVo.class);
//
//        PagePo pp = po.newQuery();
//        pp.setQuery(q);
//        iGeViewTelService.page(pp)
//        return super.page(po);
//    }


    @Override
    public DataVo<PageVo<GeViewTelEntity>> select(@RequestBody @Valid PagePo<GeViewTelEntity> po) {
        return dataPerPage(po);
    }

    @Override
    public DataVo<PageVo<GeViewTelEntity>> page(@RequestBody @Valid PagePo<GeViewTelEntity> po) {
        return dataPerPage(po);
    }

    @AjaxLogKey
    @RequestMapping(value = "/dataPerPage", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("数据权限查询数据")
    public DataVo<PageVo<GeViewTelEntity>> dataPerPage(@RequestBody @Valid PagePo<GeViewTelEntity> po) {

        PageVo<GeViewTelEntity> pageVo =  iGeViewTelService.dataPerPage(po);
        return DataVo.of(pageVo);
    }



}
